﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
 


namespace 客户端调用
{
    class CallbackHandler : WCFService_DualPlex.IUserCallback
    {
        //实现服务端的回调接口
        public void PrintSomething(string str)
        {
            Console.WriteLine(str);
        }
    }
    class Program
    {
      
        static void Main(string[] args)
        {

            //  NewMethod();
            //  NewMethod1();
            DualPlex();
        }

        /// <summary>
        /// 请求与答复
        /// </summary>
        private static void NewMethod1()
        {
            WCFService_OneWay.WCFService_OneWayClient onewayclient = new WCFService_OneWay.WCFService_OneWayClient();
            Console.WriteLine(DateTime.Now);
            onewayclient.DoWork();
            Console.WriteLine();
            Console.WriteLine(DateTime.Now);
            Console.ReadLine();
        }

        /// <summary>
        ///  单向模式
        /// </summary>
        private static void NewMethod()
        {
            WCFService_Default.WCFService_DefaultClient client = new WCFService_Default.WCFService_DefaultClient();
            Console.WriteLine(DateTime.Now);
            string result = client.ShowName("张三");
            Console.WriteLine(result);
            Console.WriteLine(DateTime.Now);
            Console.ReadLine();
           
        }

        private static void  DualPlex()
        {
            InstanceContext instanceContext = new InstanceContext(new CallbackHandler());
            WCFService_DualPlex.UserClient dualplexclient = new WCFService_DualPlex.UserClient(instanceContext);
            //  dualplex.ShowName();
            Console.WriteLine(DateTime.Now);
            string result = dualplexclient.ShowName1("李林峰");
            Console.WriteLine(result);
            Console.WriteLine(DateTime.Now);
            Console.ReadLine();

        }
    }
}
